﻿#ifndef __SERVERTYPE__
#define __SERVERTYPE__

#include <iostream>
#include <string>
#include <sstream>
#include "Vmtype.h"

namespace hw {
    struct ServerType {
        ServerType(std::string &name, const int &core, const int &memory, const int &hardware_price,
                   const int &daily_cost) : name(name), core(core), memory(memory), hardware_price(hardware_price),
                                            daily_cost(daily_cost) {};

        ServerType() = default;
        double cost_performance() {
            return (core * 0.5 + memory * 0.5) / (hardware_price * 0.4 + daily_cost) * 100;
        }

        double m_c_ratio() const {
            return 1.0 * memory / core;
        }

        bool can_fit(const Vmtype& vmtype) const {
            if (vmtype.is_double) {
                return vmtype.core <= core && vmtype.memory <= memory;
            } else {
                return (vmtype.core<<1) <= core && (vmtype.memory<<1) <= memory;
            }
        }

        std::string repr() {
            std::ostringstream buffer;
            buffer << "ServerType('" << name << ',' << core << ',' << memory << ',' << hardware_price << ','
                   << daily_cost << ')';
            std::string str = buffer.str();
            return str;
        }

        std::string name;
        int core;
        int memory;
        int hardware_price;
        int daily_cost;
    };
}; // namespace hw

#endif